//
//  SQFunctionTableViewCell.m
//  energy
//
//  Created by 周曼迪 on 2021/7/6.
//

#import "SQFunctionTableViewCell.h"

#import "SQWorkView.h"

@implementation SQFunctionTableViewCell
{
    __weak IBOutlet NSLayoutConstraint *_bg_height;
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.view_bg SQCornerLineWidth:W(1) LineColor:[UIColor colorNamed:@"f1Color"]];
    [self.view_bg SQCornerRadius:W(5)];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
}

-(void)setModel:(BaseModel<BaseCellModelProtocol> *)model{
    if (self.indexPath.row == 0) {
        self.lab_title.text = @"作业任务";
    }else if (self.indexPath.row == 1) {
        self.lab_title.text = @"隐患管理";
    }else if (self.indexPath.row == 2) {
        self.lab_title.text = @"事故应急";
    }else if (self.indexPath.row == 3) {
        self.lab_title.text = @"两外人员";
    }
    NSArray * array ;
    if (self.indexPath.row == 0) {
        if ([MLevel isEqualToString:@"1"] ) {
            array = @[@{@"pic":@"0-0",@"name":@"作业申请"},@{@"pic":@"0-1",@"name":@"作业检查"},@{@"pic":@"0-2",@"name":@"专项检查"},@{@"pic":@"0-3",@"name":@"检查记录"}];
        }else if ( [MLevel isEqualToString:@"4"]){
            array = @[@{@"pic":@"0-0",@"name":@"作业申请"},@{@"pic":@"0-1",@"name":@"作业检查"},@{@"pic":@"0-2",@"name":@"专项检查"},@{@"pic":@"0-3",@"name":@"检查记录"}];
        }else{
            array = @[@{@"pic":@"0-0",@"name":@"作业申请"},@{@"pic":@"0-1",@"name":@"作业检查"},@{@"pic":@"0-2",@"name":@"专项检查"},@{@"pic":@"0-3",@"name":@"检查记录"}];
        }
        
    }else if (self.indexPath.row == 1) {

        if ([MLevel isEqualToString:@"1"] ) {
            array = @[@{@"pic":@"1-2",@"name":@"隐患列表"},@{@"pic":@"1-3",@"name":@"隐患确认"},@{@"pic":@"1-4",@"name":@"独立隐患"},@{@"pic":@"1-5",@"name":@"隐患登记"}];
        }else if ( [MLevel isEqualToString:@"4"]){
            array = @[@{@"pic":@"1-2",@"name":@"隐患列表"},@{@"pic":@"1-0",@"name":@"隐患整改"},@{@"pic":@"1-4",@"name":@"独立隐患"},@{@"pic":@"1-5",@"name":@"隐患登记"}];
        }else{
            array =
            @[@{@"pic":@"1-2",@"name":@"隐患列表"},@{@"pic":@"1-3",@"name":@"隐患确认"},@{@"pic":@"1-0",@"name":@"隐患整改"},@{@"pic":@"1-1",@"name":@"隐患验收"},@{@"pic":@"1-4",@"name":@"独立隐患"},@{@"pic":@"1-5",@"name":@"隐患登记"}];
        }
    }else if (self.indexPath.row == 2) {
        if ([MLevel isEqualToString:@"1"] ) {
            array = @[@{@"pic":@"2-0",@"name":@"一键报警"},@{@"pic":@"2-1",@"name":@"应急响应"},@{@"pic":@"2-2",@"name":@"应急救援"},@{@"pic":@"2-3",@"name":@"应急预案"},@{@"pic":@"2-4",@"name":@"报警记录"}];
        }else if ( [MLevel isEqualToString:@"4"]){
            array = @[@{@"pic":@"2-0",@"name":@"一键报警"},@{@"pic":@"2-2",@"name":@"应急救援"},@{@"pic":@"2-3",@"name":@"应急预案"},@{@"pic":@"2-4",@"name":@"报警记录"}];
        }else{
            array = @[@{@"pic":@"2-0",@"name":@"一键报警"},@{@"pic":@"2-1",@"name":@"应急响应"},@{@"pic":@"2-2",@"name":@"应急救援"},@{@"pic":@"2-3",@"name":@"应急预案"},@{@"pic":@"2-4",@"name":@"报警记录"}];
        }
        
    }else if (self.indexPath.row == 3) {
        array = @[@{@"pic":@"3-0",@"name":@"外企人员"},@{@"pic":@"3-1",@"name":@"外包人员"}];
        
    }

    
   
    float x = 0;
    float y =48;

    for (UIView *view in self.view_bg.subviews) {
        if ([view isKindOfClass:SQWorkView.class]) {
            [view removeFromSuperview];
        }
    }
    __weak typeof(self) weakSelf =  self;
    for (int i = 0; i < array.count; i++) {
        NSDictionary * dic = array[i];
        SQWorkView * workView = [SQWorkView shareWithData:dic frameX:&x frameY:&y];
        workView.callBack = ^(id  _Nonnull data) {
            weakSelf.cellTitles(dic[@"name"]);

        };
        [self.view_bg addSubview:workView];
    }
//
    _bg_height.constant = y + 15 + (array.count == 0?:100);
    
    
}




@end
